#ifndef _ALGO_H_
#define _ALGO_H_

#include <armadillo>
#include <iostream>
#include <vector>
#include <boost/program_options.hpp>
#include <sstream>
#include "stl-helper.h"

/** Basic members of a Data class 
*    typedef datum_type;
*    setSource(<source>)
*    printTo(<destination>)
*    setLabel(<col_index>)
*    getX(<row_index>)
*    getY(<row_index>)
*/
class MatrixData 
{
public:
    /** type of a datum */
    typedef arma::vec datum_type;  

public:
    MatrixData(int labelCol = -1);
    void setSource(std::istream& istream);
    void setSource(const std::string& fname);
    void printTo(std::ostream& ostream);
    void printTo(const std::string& fname);
    void setLabel(int labelCol);

    const datum_type& getX(int rowIndex) const;
    double getY(int rowIndex) const;
    int dim() const;
    int size() const;
protected:
    /** column index of the label, -1 if no label (default) */
    int labelCol_; 
    int dim_;
    std::vector<datum_type> x_;
    std::vector<double> y_;
};


class TextResult
{
public:
    TextResult(std::ostream& os);
    TextResult(const std::string& fname);
    ~TextResult();

    //template <typename T> TextResult& operator << (const T& msg) { os() << msg << ENDL; return *this; }
    std::stringstream& operator() ();
    void flush();

protected:
    std::ostream* os_;
    std::stringstream s_;
    bool file_stream_;
    std::ostream& os();
};

#endif
